//
//  LoginViewController.m
//  WE
//
//  Created by apple on 15/11/24.
//  Copyright © 2015年 UNOHACHA. All rights reserved.
//

#import "LoginViewController.h"
#import "ToolUtil.h"
#import "Size.h"
#import "VerifyViewController.h"


@interface LoginViewController ()<UITextFieldDelegate>

@property (nonatomic, strong)UITextField *numbaerText;
@property (nonatomic, strong)UITextField *passWordText;

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
//    UINavigationBar *naBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 20, WindowWidth, 44)];
//    naBar.backgroundColor = [UIColor clearColor];
//    [self.view addSubview:naBar];
//    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake((WindowWidth - 100)/2, 0, 100, 44)];
//    titleLabel.text = @"用户登录";
//    titleLabel.font = FONT(17);
//    titleLabel.backgroundColor = [UIColor whiteColor];
//    titleLabel.textColor = [UIColor blackColor];
//    [naBar addSubview:titleLabel];
//    
//    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    backButton.frame = CGRectMake(0, 0, 40, 44);
//    
//    UIImageView *backImage = [[UIImageView alloc] initWithFrame:CGRectMake(10*Width, 12*Height, 20*Width, 20*Height)];
//    backImage.image = [UIImage imageNamed:@"Image"];
//    
//    backButton.backgroundColor = [UIColor whiteColor];
//    [backButton addTarget:self action:@selector(pressBackButton) forControlEvents:UIControlEventTouchUpInside];
//    [backButton addSubview:backImage];
//    [naBar addSubview:backButton];
    
    self.navigationItem.title = @"用户登录";
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIView *upView = [[UIView alloc] initWithFrame:CGRectMake(0, 64, WindowWidth, 50*Height)];
    [self.view addSubview:upView];
    
    UILabel *upLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, WindowWidth, 50*Height)];
    upLabel.text = @"挂号网账号可直接登录";
    upLabel.font = FONT(14);
    upLabel.textAlignment = NSTextAlignmentCenter;
    upLabel.textColor = [UIColor blackColor];
    upLabel.backgroundColor = [UIColor colorWithRed:229/255. green:229/255. blue:229/255. alpha:1.0];
    [upView addSubview:upLabel];
    
    UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(15*Width, 60*Height +64, 20*Width, 20*Height)];
    imageV.image = [UIImage imageNamed:@"login"];
    
    [self.view addSubview:imageV];
    
    UIImageView *imagev = [[UIImageView alloc] initWithFrame:CGRectMake(15*Width, 100*Height +64, 20*Width, 20*Height)];
    imagev.image = [UIImage imageNamed:@"passWord"];
    
    [self.view addSubview:imagev];
    
    self.numbaerText = [[UITextField alloc] initWithFrame:CGRectMake(50*Width, 55*Height + 64, WindowWidth - 50*Width, 30*Height)];
    [ToolUtil createLine:90*Height +64 superView:self.view lift:50*Width width:WindowWidth - 50*Width hight:1*Height color:[UIColor grayColor]];
    self.passWordText = [[UITextField alloc] initWithFrame:CGRectMake(50*Height, 95*Height +64, WindowWidth - 50*Width, 30*Height)];
    self.numbaerText.placeholder = @"登录名或手机号";
    
    self.passWordText.placeholder = @"密码";
    self.passWordText.font = FONT(14);
    self.numbaerText.font = FONT(14);
    self.numbaerText.delegate = self;
    self.passWordText.delegate = self;
//    self.numbaerText.textColor = [UIColor grayColor];
//    self.passWordText.textColor = [UIColor grayColor];
    
//    self.numbaerText.textAlignment = NSTextAlignmentNatural;
//    self.passWordText.textAlignment = NSTextAlignmentJustified;
    [self.view addSubview:self.numbaerText];
    [self.view addSubview:self.passWordText];
    
    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 130*Height +64, WindowWidth,537*Height- 64)];
    bottomView.backgroundColor = [UIColor colorWithRed:229/255. green:229/255. blue:229/255. alpha:1.0];
    
    [self.view addSubview:bottomView];
    
    UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
    loginButton.frame = CGRectMake(10*Width, 150*Height +64, 355*Width, 40*Height);
    [loginButton setTitle:@"马上登录" forState:UIControlStateNormal];
    [loginButton addTarget:self action:@selector(pressLoginButton) forControlEvents:UIControlEventTouchUpInside];
    loginButton.backgroundColor = [UIColor blueColor];
    [loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.view addSubview:loginButton];
    
    UIButton *registerButton = [UIButton buttonWithType:UIButtonTypeCustom];
    registerButton.frame = CGRectMake(WindowWidth/4, 220*Height +64, WindowWidth/4, 20*Height);
    [registerButton setTitle:@"注册新账号" forState:UIControlStateNormal];
    registerButton.titleLabel.font = FONT(14);
    [registerButton addTarget:self action:@selector(pressRegisterButton) forControlEvents:UIControlEventTouchUpInside];
    registerButton.backgroundColor = [UIColor colorWithRed:229/255. green:229/255. blue:229/255. alpha:1.0];
    [registerButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [self.view addSubview:registerButton];
    
    [ToolUtil createVerticalLine: 220*Height +64 superView:self.view lift:WindowWidth/2 height:20*Height];
    UIButton *findButton = [UIButton buttonWithType:UIButtonTypeCustom];
    findButton.frame = CGRectMake(WindowWidth/2+1, 220*Height +64,WindowWidth/4-1 , 20*Height);
    findButton.titleLabel.font = FONT(14);
    [findButton setTitle:@"忘记密码?" forState:UIControlStateNormal];
    [findButton addTarget:self action:@selector(pressFindButton) forControlEvents:UIControlEventTouchUpInside];
    findButton.backgroundColor = [UIColor colorWithRed:229/255. green:229/255. blue:229/255. alpha:1.0];
    [findButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [self.view addSubview:findButton];
    
}

- (void)pressRegisterButton{
    
    VerifyViewController *vVC = [[VerifyViewController alloc] init];
    vVC.string = @"注册";
    [self.navigationController pushViewController:vVC animated:YES];
}


- (void)pressFindButton{
    VerifyViewController *vVC = [[VerifyViewController alloc] init];
    vVC.string = @"找回密码";
    [self.navigationController pushViewController:vVC animated:YES];
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    
    [self.view endEditing:YES];
    return YES;
}


- (void)pressLoginButton{
    if ([self.numbaerText.text isEqualToString:@"111"] && [self.passWordText.text isEqualToString:@"111"]) {
        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
        //登陆成功后把用户名和密码存储到UserDefault
        //NSString *name = [userDefaults objectForKey:@"name"];
        [userDefaults setObject:@"111" forKey:@"name"];
        [self.navigationController popViewControllerAnimated:YES ];

    }
    
}
- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = NO;
    
}


- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    
    
    
    return YES;
}

- (void)pressBackButton{
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
